//
//  SubjectRecommendCell.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/10/29.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "SubjectRecommendCell.h"
#import "SpecialRecommendationModel.h"
@interface SubjectRecommendCell()
@property (weak, nonatomic) IBOutlet UILabel *nameL;
@property (weak, nonatomic) IBOutlet UIImageView *leftIV;
@property (weak, nonatomic) IBOutlet UIImageView *rightIV;
@property (weak, nonatomic) IBOutlet UILabel *leftL;
@property (weak, nonatomic) IBOutlet UILabel *rightL;
@property (weak, nonatomic) IBOutlet UILabel *leftDetailL;
@property (weak, nonatomic) IBOutlet UILabel *rightDetailL;
- (IBAction)leftBtn:(UIButton *)sender;
- (IBAction)rightBtn:(UIButton *)sender;

@end
static NSString *identifier = @"SubjectRecommendCell";
@implementation SubjectRecommendCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.leftL.font = [UIFont systemFontOfSize:14];
    self.leftL.textColor = kLabel16Color;
    self.rightL.font = [UIFont systemFontOfSize:14];
    self.rightL.textColor = kLabel16Color;
    self.leftDetailL.font = [UIFont systemFontOfSize:12];
    self.leftDetailL.textColor = kLabel153Color;
    self.rightDetailL.font = [UIFont systemFontOfSize:12];
    self.rightDetailL.textColor = kLabel153Color;
    self.nameL.font = [UIFont systemFontOfSize:12];
    self.nameL.backgroundColor = kOrangeBg;
}
+(instancetype)cellNibWithTableView:(UITableView *)tableView
{
    SubjectRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        [tableView registerNib:[UINib nibWithNibName:@"SubjectRecommendCell" bundle:nil] forCellReuseIdentifier:identifier];        
    }
    cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    return cell;
}
- (void)setName:(NSString *)name
{
    _name = name;
    self.nameL.text = name;
}

- (void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
    if (indexPath.row == 0) {
        self.name = @"需求";
    }else {
        self.name = @"服务";
    }
}
- (IBAction)leftBtn:(UIButton *)sender {
    XLog(@"self.specialMuta[0]:%@",self.subjectDemandArray[0]);
    if (self.indexPath.row == 0) {
        if ([self.delegate respondsToSelector:@selector(subjectRecommendCell:withTag:withIndexPath:withSpecialModel:)]) {
            [self.delegate subjectRecommendCell:self withTag:sender.tag withIndexPath:self.indexPath withSpecialModel:self.subjectDemandArray[0]];
        }
        
    }else {
        if ([self.delegate respondsToSelector:@selector(subjectRecommendCell:withTag:withIndexPath:withSpecialModel:)]) {
            [self.delegate subjectRecommendCell:self withTag:sender.tag withIndexPath:self.indexPath withSpecialModel:self.subjectServiceArray[0]];
        }
    }
}

- (IBAction)rightBtn:(UIButton *)sender {
    if (self.indexPath.row == 0) {
        if ([self.delegate respondsToSelector:@selector(subjectRecommendCell:withTag:withIndexPath:withSpecialModel:)]) {
            [self.delegate subjectRecommendCell:self withTag:sender.tag withIndexPath:self.indexPath withSpecialModel:self.subjectDemandArray[1]];
        }
        
    }else {
        if ([self.delegate respondsToSelector:@selector(subjectRecommendCell:withTag:withIndexPath:withSpecialModel:)]) {
            [self.delegate subjectRecommendCell:self withTag:sender.tag withIndexPath:self.indexPath withSpecialModel:self.subjectServiceArray[1]];
        }
    }
}
- (void)setSubjectDemandArray:(NSArray *)subjectDemandArray
{
    _subjectDemandArray = subjectDemandArray;
    if (self.indexPath.row == 0) {
        SpecialRecommendationModel *modelL = subjectDemandArray[0];
        SpecialRecommendationModel *modelR = subjectDemandArray[1];
        XLog(@"modelL:%@",modelL.ids);
        [self.leftIV sd_setImageWithURL:[NSURL URLWithString:modelL.icon] placeholderImage:[UIImage imageNamed:@""]];
        [self.rightIV sd_setImageWithURL:[NSURL URLWithString:modelR.icon] placeholderImage:[UIImage imageNamed:@""]];
        self.leftL.text = modelL.title;
        self.rightL.text = modelR.title;
        self.leftDetailL.text = [NSString stringWithFormat:@"共包含%ld条内容",modelL.idSize];
        self.rightDetailL.text = [NSString stringWithFormat:@"共包含%ld条内容",modelR.idSize];
        
    }
    
}
- (void)setSubjectServiceArray:(NSArray *)subjectServiceArray
{
    _subjectServiceArray = subjectServiceArray;
    if (self.indexPath.row == 1) {
        SpecialRecommendationModel *modelL = subjectServiceArray[0];
        SpecialRecommendationModel *modelR = subjectServiceArray[1];
        XLog(@"modelL:%@",modelL.ids);
        [self.leftIV sd_setImageWithURL:[NSURL URLWithString:modelL.icon] placeholderImage:[UIImage imageNamed:@""]];
        [self.rightIV sd_setImageWithURL:[NSURL URLWithString:modelR.icon] placeholderImage:[UIImage imageNamed:@""]];
        self.leftL.text = modelL.title;
        self.rightL.text = modelR.title;
        self.leftDetailL.text = [NSString stringWithFormat:@"共包含%ld条内容",modelL.idSize];
        self.rightDetailL.text = [NSString stringWithFormat:@"共包含%ld条内容",modelR.idSize];
        
    }
}

@end
